<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Model\User;

class RegisterController extends Controller
{
	public function index(){
		return view('register/index');
	}

	public function register(Request $request){
		$this->validate($request,[
			'name' => 'required|min:3|unique:users,name',
			'email' => 'required|email|unique:users,email',
			'password' => 'required|min:6|max:12|confirmed',
			]);
		$name = request('name');
		$email = request('email');
		$password = bcrypt(request('password'));

		$user = new user();
		$user->name = $name;
		$user->email = $email;
		$user->password = $password;
		$user->save();

		$user = request(['email','password']);
		if(\Auth::attempt($user)){
			return redirect('posts');
		}
	}
}